<template>
  <div>
    <h1 align="center">房号添加</h1>

    <table class="table table-bordered">
      <tbody>
        <tr>
          <td align="right">房号名称</td>
          <td><input type="text" v-model="queryInfo.houseNoName"></td>
        </tr>

        <tr>
          <td align="right">房型</td>
          <td>
            <select v-model="queryInfo.houseTypeId">
              <option value="0">请选择</option>
              <option :value="1">大床房</option>
              <option :value="2">双人房</option>
              <option :value="3">总统套房</option>
            </select>
          </td>
        </tr>

        <tr>
          <td align="right">房型状态</td>
          <td>
            <select v-model="queryInfo.houseTypeState">
              <option value="0">请选择</option>
              <option :value="1">空闲</option>
              <option :value="2">已预约</option>
              <option :value="3">已入住</option>
            </select>
          </td>
        </tr>

        <tr>
          <td align="right">房间价格</td>
          <td><input type="text" v-model="queryInfo.price"></td>
        </tr>

        <tr>
          <td align="right">房号状态</td>
          <td>
            <input type="radio" name="status" :value="1" v-model="queryInfo.isDeleted">上架 
            <input type="radio" name="status" :value="0" v-model="queryInfo.isDeleted">下架
          </td>
        </tr>


        <tr>
          <td align="right"></td>
          <td><input type="button" value="提交" @click="ok"></td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted} from 'vue'
import { useRoute, useRouter } from 'vue-router'
import axios from 'axios'
const route = useRoute()
const router = useRouter()

let queryInfo = reactive({
  houseTypeId: '',
  houseNoName: '',
  houseTypeState: '',
  price: '',
  isDeleted: 1
})


const ok = () => {
  if(queryInfo.houseNoName=='')
  {
    alert('房号不能为空')
    return;
  }
  axios({
    url:'/api/HouseNo/Add',
    method:'post',
    data:queryInfo
  })
  .then((res)=>{
    console.log(res)
    if(res.data == -1){
      alert('房号已存在');
      return;
    }
    if(res.data == 1){
      alert('添加成功');
      router.push('/housenolist')
    }
    if(res.data == -2){
      alert('添加失败');
      return;
    }
  })
  .catch((err)=>{
    console.log(err)
  })
}

</script>

<style scoped>

</style>